$(document).ready(function() {
	init(1);
});
	
//默认加载  
function init(pageNo){
	//获取信息列表
	$("#thislist").html("");
	$.ajax({
		url: urlcore + "/api/user/jpa/cardPage?pageNum="+pageNo+"&pageSize="+pageSize+"&userType="+2,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
				//i表示在data中的索引位置，n表示包含的信息的对象
				$.each(data.data.list,function(i,n){	
					var id = n.id;
					var thislist = 
					'	<tr>'+				
					'		<td>'+(i+1)+'</td>'+
					'		<td>'+n.realName+'</td>'+
					'		<td><img width="150px" height="150px" src="'+n.healthCard+'"></td>'+
					'		<td>'+			
					'			<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="pass('+id+')">审核通过</a>'+
					'			<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="fail('+id+')">审核失败</a>'+	
					'		</td>'+
					'	</tr>';
					$('#thislist').append(thislist);	
														
				});
				$('#thiscount').text(data.data.total);
				$("#pager").pager({
					pagenumber: pageNo, 
					pagecount:data.data.pages,
					totalcount:data.data.total,
					buttonClickCallback: PageClick
				}); 
				
			} else if (data.code == 'OVERTIME'){
				var thisUrl = window.location.href;
				if (thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href="login.html";
				}

			} else {
				if (data.msg != '空数据') {
					alert(data.msg)
				}else{
					$('#thiscount').text(0);
				}
			}

		},
		error:function() {
			alert("error");
		}
	});
}
//回调函数  
PageClick = function(pageclickednumber) {  
    init(pageclickednumber); 
}

/**
 * 审核通过
 */
function pass(id){
	$.ajax({
        url: urlcore + "/api/user/setCardPass?userId="+id+"&userType="+2,
        type: "get",
        dataType: 'json',
        contentType: "application/json;charset=utf-8",
        success:function(data){
            if (data.success == true) {
            	location.reload();
            } else if (data.code == 'OVERTIME'){
                    var thisUrl = window.location.href;
                    if (thisUrl.indexOf('login.html') <= -1) {
                        top.window.location.href="login.html";
                    }
                } else {
                    alert(data.msg);
                }
        },
        error:function() {
            /* Act on the event */
            alert("error");
        }
    });
}

/**
 * 审核失败
 */
function fail(id){
	$.ajax({
        url: urlcore + "/api/user/setCardFail?userId="+id+"&userType="+2,
        type: "get",
        dataType: 'json',
        contentType: "application/json;charset=utf-8",
        success:function(data){
            if (data.success == true) {
            	location.reload();
            } else if (data.code == 'OVERTIME'){
                    var thisUrl = window.location.href;
                    if (thisUrl.indexOf('login.html') <= -1) {
                        top.window.location.href="login.html";
                    }
                } else {
                    alert(data.msg);
                }
        },
        error:function() {
            /* Act on the event */
            alert("error");
        }
    });
}